/**
 * ConfigFtpData.java
 * 版权所有(C) 2013
 * 创建者:cuiran 2013-11-27 下午3:58:49
 */
package com.ghyf.mplay.net.data;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.Serializable;

import com.ghyf.mplay.net.common.RecvBase;
import com.ghyf.mplay.util.LogUtil;

/**
 * FTP_DATA
 * @author cuiran
 * @version 1.0.0
 */
public class ConfigFtpData implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4141086666936707239L;
	private static final String TAG="ConfigFtpData";
	public static final int textContentLength =	1024;
	public static final int fileLength =	256;
	private short cmdId;
	private byte isValid;
	private String ip;
	private static final int iplength=15;
	private int port;
	private String username;
	private static final int usernamelength=40;
	private String password;
	private static final int passwordlength=40;
	
	private byte softwareMode;
	private String softwareFilename;
	private byte configMode;
	private String configFilename;
	
	private byte listMode;
	private String listFilename;
	
	
	private byte logMode;
	private String logType;
	private static final int logTypelength=10;
	private String logDate;
	private static final int logDatelength=10;
	private String reserved;
	
	/**
	 * 获取FTP_DATA <br>
	 * 2013-11-27 下午4:16:01
	 * @param buf_recv
	 * @param packetHeaderLength
	 * @param setConfigDataLength
	 * @return
	 *
	 */
	public boolean getFtpData(byte [] buf_recv, int packetHeaderLength, int setConfigDataLength,int cmdID){
		ByteArrayInputStream baInPacketData = new ByteArrayInputStream(buf_recv, packetHeaderLength, setConfigDataLength);
		DataInputStream dInData = new DataInputStream(baInPacketData);
		byte[] buf_temp = new byte[textContentLength];
		try{
			isValid=dInData.readByte();
			dInData.read(buf_temp, 0, iplength);
			ip=new String(buf_temp,0,iplength,RecvBase.charset).trim();
			port=dInData.readInt();
			dInData.read(buf_temp, 0, usernamelength);
			username=new String(buf_temp,0,usernamelength,RecvBase.charset).trim();
			dInData.read(buf_temp, 0, passwordlength);
			password=new String(buf_temp,0,passwordlength,RecvBase.charset).trim();
			switch(cmdID)
			{
			case RecvBase.CMD_FILE_SETCONFIG:
				softwareMode=dInData.readByte();
				dInData.read(buf_temp,0,fileLength);
				softwareFilename=new String(buf_temp,0,fileLength,RecvBase.charset).trim();
				configMode=dInData.readByte();
				dInData.read(buf_temp,0,fileLength);
				configFilename=new String(buf_temp,0,fileLength,RecvBase.charset).trim();
				
				break;
			case RecvBase.CMD_FILE_SETLIST:
				listMode=dInData.readByte();
				dInData.read(buf_temp,0,fileLength);
				listFilename=new String(buf_temp,0,fileLength);
				
				break;
			case RecvBase.CMD_FILE_GETLOG:
				logMode=dInData.readByte();
				dInData.read(buf_temp,0,logTypelength);
				logType=new String(buf_temp,0,logTypelength);
				dInData.read(buf_temp,0,logDatelength);
				logDate=new String(buf_temp,0,logDatelength);
				/**
				 * TODO Reserved 预留尚未处理
				 */
				break;
			}
			
			
			
		}catch(Exception e){
			LogUtil.e(TAG, "getftpdata error", e);
		}
		
		return true;
	}
	
	
	
	/**
	 * @return the ip
	 */
	public String getIp() {
		return ip.trim();
	}


	

	/**
	 * @return the cmdId
	 */
	public short getCmdId() {
		return cmdId;
	}



	/**
	 * @param cmdId the cmdId to set
	 */
	public void setCmdId(short cmdId) {
		this.cmdId = cmdId;
	}



	/**
	 * @param ip the ip to set
	 */
	public void setIp(String ip) {
		this.ip = ip;
	}



	/**
	 * @return the port
	 */
	public int getPort() {
		return port;
	}



	/**
	 * @param port the port to set
	 */
	public void setPort(int port) {
		this.port = port;
	}



	/**
	 * @return the username
	 */
	public String getUsername() {
		return username.trim();
	}



	/**
	 * @param username the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}



	/**
	 * @return the password
	 */
	public String getPassword() {
		return password.trim();
	}



	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}



	/**
	 * @return the softwareMode
	 */
	public byte getSoftwareMode() {
		return softwareMode;
	}



	/**
	 * @param softwareMode the softwareMode to set
	 */
	public void setSoftwareMode(byte softwareMode) {
		this.softwareMode = softwareMode;
	}



	/**
	 * @return the softwareFilename
	 */
	public String getSoftwareFilename() {
		return softwareFilename.trim();
	}



	/**
	 * @param softwareFilename the softwareFilename to set
	 */
	public void setSoftwareFilename(String softwareFilename) {
		this.softwareFilename = softwareFilename;
	}



	/**
	 * @return the configMode
	 */
	public byte getConfigMode() {
		return configMode;
	}



	/**
	 * @param configMode the configMode to set
	 */
	public void setConfigMode(byte configMode) {
		this.configMode = configMode;
	}



	/**
	 * @return the configFilename
	 */
	public String getConfigFilename() {
		return configFilename.trim();
	}



	/**
	 * @param configFilename the configFilename to set
	 */
	public void setConfigFilename(String configFilename) {
		this.configFilename = configFilename;
	}

	

	/**
	 * @return the listMode
	 */
	public byte getListMode() {
		return listMode;
	}



	/**
	 * @param listMode the listMode to set
	 */
	public void setListMode(byte listMode) {
		this.listMode = listMode;
	}



	/**
	 * @return the listFilename
	 */
	public String getListFilename() {
		return listFilename.trim();
	}



	/**
	 * @param listFilename the listFilename to set
	 */
	public void setListFilename(String listFilename) {
		this.listFilename = listFilename;
	}



	public String toString(){
		return new String("isValid="+isValid+" ip="+ip+" port="+port+" " +
				"username="+username+" password="+password+" " +
						"softwareMode="+softwareMode+" softwareFilename="+softwareFilename+"" +
								" configMode="+configMode+"　configFilename＝"+configFilename+" " +
										"listMode="+listMode+" listFilename="+listFilename+" " +
												"logMode="+logMode+" logType="+logType+" logDate="+logDate+" reserved="+reserved);
	}
	public String toString1(){
		return " ip="+ip+" port="+port+" username="+username+" password="+password;
	}
}
